#!/bin/bash

ifeq (,$(TOP_DIR))
TOP_DIR := $(shell pwd)/..
CURRENT_DIR := $(shell pwd)
else
CURRENT_DIR := $(TOP_DIR)/tests
endif

OBJS := $(CURRENT_DIR)/source/gtest_*.c

INCLUDE_PATH := -I $(TOP_DIR)/include/
INCLUDE_PATH += -I $(TOP_DIR)/tests/include/
INCLUDE_PATH += -I /usr/include/glib-2.0
INCLUDE_PATH += -I /usr/lib/x86_64-linux-gnu/glib-2.0/include
INCLUDE_PATH += -I /usr/lib64/glib-2.0/include

LDFLAGS := -L$(TOP_DIR)/output/
LIBS := -lqtsm
LIBS += -lssl -lcrypto
LIBS += -lglib-2.0

TARGET := $(CURRENT_DIR)/gtest_libqtsm

ifeq (,$(CC))
CC := gcc
endif

GCC_CHOOSE := -W -Os -g -Wl,-z,noexecstack
GCC_CHOOSE += -Wl,-z,relro,-z,now
GCC_CHOOSE += -fstack-protector-all
GCC_CHOOSE += -fsanitize=address

gtest_libqtsm:
	@echo "---------------------------------------- Start Make QTSM Samples -------------------------------------------"
	$(CC) $(GCC_CHOOSE) $(INCLUDE_PATH) $(OBJS) $(LIBS) $(LDFLAGS) -o $(TARGET)
	@echo "---------------------------------------- End Make QTSM Samples -------------------------------------------"

clean:
	rm $(TARGET) -rf
